// pages/my/my.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    phoneshow:false,
    loginShow:false,
    login:false,
    phone: false,
    userInfo:{},
    whetherSetPayPwd:true,
  },
  login() {
    if (this.data.login) {
      this.toggle('phoneshow', true)
      this.selectComponent('#phone').showClose()
    } else {
      this.toggle('loginShow', true)
      this.selectComponent('#login').showClose()
    }
  },
  toggleToast(e) {
    console.log(e.detail)
    if (!e.detail.loginShow) {
      this.toggle('loginShow', false)
    }
    this.getUserInfo()
  },
  toggleToast1(e) {
    console.log(e.detail)
    if (!e.detail.phoneshow) {
      this.toggle('phoneshow', false)
    }
    this.getUserInfo()
  },
  toggle(type, val) {
    this.setData({
      [type]: val
    });
  },
  gologs(){
    wx.navigateTo({
      url: '/pages/logs/logs'
    });
  },
  gomessageList(){
    wx.navigateTo({
      url: '/pages/messageList/messageList'
    });
  },
  goblessingList(){
    wx.navigateTo({
      url: '/pages/blessingList/blessingList',
    })
  },
  gomymoney(){
    wx.navigateTo({
      url: '/pages/myMoney/myMoney'
    });
  },
  goabout(){
    wx.navigateTo({
      url: '/pages/about/about'
    });
  },
  pswd() {
      if (this.data.whetherSetPayPwd) {
        wx.navigateTo({
          url: '/pages/password/password?xg=' + 1
        })
      } else {
        wx.navigateTo({
          url: '/pages/password/password'
        })
      }
  },
  //获取是否有密码
  getIspswd() {
    var that = this
    app.req({
      url: 'blessmini/user/whetherSetPayPwd',
      data: {
      },
      method: 'POST',
      success: function (res) {
        console.log('密码', res);
        if (res.code == 200) {
          that.setData({
            whetherSetPayPwd: res.data.whetherSetPayPwd
          })
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this
    that.getUserInfo()
  },
  getUserInfo() {
    var that = this
        if (wx.getStorageSync('uid') == '') {
          that.toggle("login", false);
        } else {
          that.toggle("login", true);
          var phone = wx.getStorageSync("phone")
          if (phone == '') {
            that.toggle("phone", true);
          } else {
            that.toggle("phoneshow", false);
            that.toggle("loginShow", false);
            that.toggle("phone", false);
          }
          app.getUserInfo(function (userInfo) {
            that.toggle("userInfo", userInfo);
            that.getIspswd()
          }, true)
        }
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: '您有一份一起来往送来的祝福，请查收！',
      path: '/pages/index/index',
    }
  }
})